import React, { forwardRef, useState, useImperativeHandle, useRef, useEffect } from "react";
import { Menu, Space } from '@bytedance/mona-ui';
import { useAppDispatch } from "~store"
import { getBuyCounpStatusAction } from "~store/controller/autoCounps"
import RepeatProdect from "./repeatProdect"
function ProdectOptimization(props, ref) {
    const [current, setcurrent] = useState(props.actstr || 'repeatProdect')
    const { setFooterStatus } = props
    // const [current, setcurrent] = useState('AutoSetCoupon')
    const dispatch = useAppDispatch()
    type ChildMethods = {
        // 子组件暴露给父组件的方法
        someMethod: () => void;
    };
    const childRef = useRef<ChildMethods>(null);
    function someMethod() {
        if (childRef.current) {
            childRef.current?.someMethod();
        }
    }
    useImperativeHandle(ref, () => ({
        someMethod,
    }));
    // useEffect(() => {
    //     if (!props || !props.setFooterStatus) return
    //     if (current === 'addCoupon') {
    //         props.setFooterStatus(true)
    //     } else {
    //         props.setFooterStatus(false)
    //     }
    // }, [current])
    // addNewConter()
    // setFooterStatus && setFooterStatus(false)
    return (<Space direction="vertical" style={{
        width: '100%'
    }} size={18}>
        <Menu onClick={(e) => {
            // console.log('e', e)
            // if (e.key === 'AutoSetCoupon') {
            //     // getBgCoupOuterTuis('')
            //     // // addNewConter()
            //     // loginShopGetShopInfos()
            //     dispatch(getBuyCounpStatusAction(''))
            // }
            setcurrent(e.key)
        }} selectedKeys={[current]} mode="horizontal">
            <Menu.Item key="repeatProdect">
                重复铺货
            </Menu.Item>
            {/* <Menu.Item key="repeatProdect">
                管理优惠券
            </Menu.Item>
            <Menu.Item key="AutoSetCoupon">
                自动设置优惠券
            </Menu.Item> */}
        </Menu>
        <div className={current === 'repeatProdect' ? 'show' : 'hide'}>
            <RepeatProdect ref={childRef} />
        </div>
    </Space>)
}
export default forwardRef(ProdectOptimization)